package cn.buk.tms.eotms.controller;

import cn.buk.common.dto.CommonDto;
import cn.buk.tms.eotms.dto.VasOrderDto;
import cn.buk.tms.eotms.sc.SearchFlightOrderCriteria;
import cn.buk.tms.eotms.service.VasOrderService;
import java.util.List;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yfdai
 */
@RestController
public class VasOrderController extends BaseController {

  @Autowired
  private VasOrderService vasOrderService;

  /**
   * 查找vas(非保险）订单
   *
   * @return
   */
  @RequestMapping("/vas/orders")
  public CommonDto<VasOrderDto> searchVasOrders(HttpServletRequest request,
      @ModelAttribute("sc") SearchFlightOrderCriteria sc
  ) {
    List<VasOrderDto> datas = vasOrderService.searchVasOrders(getUserId(request), sc, false);

    CommonDto<VasOrderDto> commonDto = new CommonDto<>();
    commonDto.setDataList(datas);
    commonDto.setPage(sc.getPage());

    return commonDto;
  }

  /**
   * 查找vas(保险）订单
   *
   * @return
   */
  @RequestMapping("/insurance/orders")
  public CommonDto<VasOrderDto> searchInsuranceOrders(HttpServletRequest request,
      @ModelAttribute("sc") SearchFlightOrderCriteria sc
  ) {
    List<VasOrderDto> datas = vasOrderService.searchVasOrders(getUserId(request), sc, true);

    CommonDto<VasOrderDto> commonDto = new CommonDto<>();
    commonDto.setDataList(datas);
    commonDto.setPage(sc.getPage());

    return commonDto;
  }

  /**
   * 获取vas订单详情
   */
  @RequestMapping({"/vas/order/{id}", "/insurance/order/{id}"})
  public VasOrderDto getVasOrderDetail(HttpServletRequest request,
      @PathVariable("id") int id
  ) {
    return vasOrderService.getVasOrderById(getUserId(request), id);
  }
}
